import Vue from 'vue'
import Vuex from 'vuex'
// import { userInfo } from '@/assets/api'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        users: null,
        product: null,
        mine:null,
        token: sessionStorage.getItem('token'),
        myNote: [],
        searchPro: [],
        historyPro: [],
        currentChat:null,
        chatList:[
            {
                imgUrl:require('../assets/img/users/head/yataodawang.jpg'),
                userName:'牙套大王',
                contentList:[
                    {
                        role:'other',
                        content:'好久不见'
                    },
                    {
                        role:'mine',
                        content:'是呀是呀'
                    },
                ],
            }
        ]
    },
    mutations: {
        setToken(state,obj){ 
            state.token = obj.token
        },
        editMine(state,obj){
            state.mine.name = obj.name;
            state.mine.url = obj.imgs;
            state.mine.num = obj.num;
            state.mine.sex = obj.sex;
            state.mine.birthday = obj.date;
            state.mine.brief = obj.brief;
        },
        setUsers(state,param){
            state.users = param
        },
        setProduct(state,param){
            state.product = param
        },
        setCollection(state,param){
            state.product[param.i].isCollect = param.isCollect
        },
        setNoteLike(state,param){
            state.users[param.i].isLike = param.isLike
            state.users[param.i].fabulous = param.isLike?state.users[param.i].fabulous+1:state.users[param.i].fabulous-1
            console.log(state.users[param.i].fabulous);
        },
        setNoteCollect(state,param){
            state.users[param.i].isCollect = param.isCollect
            state.users[param.i].collection = param.isCollect?state.users[param.i].collection+1:state.users[param.i].collection-1
        },
        getCurrentChat(state,user){
            state.currentChat = user
        },
        setMine(state,param){
            state.mine = param
        }
    },
})
